#ifndef XTCP_BUFFER_H
#define XTCP_BUFFER_H

#include "xnet_tiny.h"

// tail-->next  是已经发送，但为被确认的缓冲区
// next-->front 是未被发送，已经写入缓冲区的数据
// data_count = front - tail 是循环数组，就拿一个数据存起来，避免讨论
// data_count = next - tail
#define XTCP_CFG_RTX_BUF_SIZE 1024

typedef struct _xtcp_buffer_t
{
    uint16_t data_count, unack_count;
    uint16_t front, next, tail;
    uint8_t data[XTCP_CFG_RTX_BUF_SIZE];
} xtcp_buffer_t;

void tcp_buffer_init(xtcp_buffer_t * buffer);
uint16_t tcp_buffer_free_size(xtcp_buffer_t * buffer);
uint16_t tcp_buffer_wait_send_size(xtcp_buffer_t * buffer);
void tcp_buffer_add_acked_count(xtcp_buffer_t *buffer,uint16_t size);

uint16_t tcp_buffer_write(xtcp_buffer_t * tcp_buffer,uint8_t * from,uint16_t size);
uint16_t tcp_buffer_read(xtcp_buffer_t * tcp_buffer,uint8_t * to,uint16_t size);
//发送


#endif